﻿/// <reference path="underscore.js" />
/// <reference path="jquery-2.1.3.js" />

ExecuteOrDelayUntilScriptLoaded(getPageContextInfo, "core.js");
function getPageContextInfo() {
    console.log(_spPageContextInfo.systemUserKey);
}

$(document).ready(function () {
    var $sidebar = $("#sideNavBox");
    var $list = $(".ms-core-listMenu-root", $sidebar);
    $list.on("click", "li", function (e) {
        var $li = $(e.target).closest("li");

        // Slide
        $.each($list.find("ul:visible"), function () {
            if ($.inArray(this, $li.parentsUntil($list, "ul")) == -1) {
                if (!$(this).parent("li:first").is($li)) {
                    $(this).slideUp();
                }
            }
        })
        $li.children("ul").slideToggle();

        // Styles
        $list.find("li").removeClass("selected").removeClass("open");
        $li.addClass("selected");
        $li.parentsUntil($list, 'li').addClass("selected").addClass("open");
        return false;
    });

    var $toggle = $(".sidebar-toggle", $sidebar);
    $toggle.on("click", function (e) {
        $i = $(e.target).closest("i");
        $i.toggleClass("fa-angle-double-left").toggleClass("fa-angle-double-right");
        $sidebar.toggleClass("menu-min");
    })
})